// 
// Decompiled by Procyon v0.5.30
// 

package com.baturu.vin.benz.dto.footnote;

import com.baturu.vin.benz.dto.BenzVinInfoDTO;
import com.baturu.vin.benz.service.impl.util.BenzStringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

@Slf4j
public class FootnoteRev9Serial extends FootnoteRev9 {
    private static long serialVersionUID = 3978990951023064887L;
    private String cab;
    private String engine;
    private String chassis;
    private String xferCase;
    private String platForm;
    private String steer;
    private String fAxle;
    private String rAxle;
    public String transmission;
    private String herstellar;
    private String plantCodes;
    private String ident;
    private String date;
    private String modelyr;
    private char plusIdent;
    private char minusIdent;
    private String extraIdents;
    private int rowNumber;
    private boolean validByPlusIdent;
    private boolean inValidByMinusIdent;
    private boolean plantCodeOnlyFN;

    public FootnoteRev9Serial() {
        this.rowNumber = 0;
        this.validByPlusIdent = false;
        this.inValidByMinusIdent = false;
        this.plantCodeOnlyFN = false;
        this.isSerial = true;
        this.validByPlusIdent = false;
        this.inValidByMinusIdent = false;
    }

    @Override
    public void setText(String string) {
        super.setText(string);
        this.setValues();
    }


    private boolean isValidByPlusIdent() {
        return validByPlusIdent;
    }

    public boolean isInValidByMinusIdent() {
        return inValidByMinusIdent;
    }


    @Override
    public int isValid(FootnoteList fnl, BenzVinInfoDTO benzVinInfoDTO, int statusCKD) {
        int returnValue = 0;
        if (this.hasBeenChecked) {
            return this.lastValidReturnValue;
        }
        this.plantCodes = fnl.getPlants();
        if (!this.isDoIdentfilter(this.getAbbr())) {
            return this.setValid(8);
        }
        int abbr = this.translateABBR(this.getAbbr());
        String serialIdent = this.loadDatacardValues(abbr, benzVinInfoDTO);
        returnValue = this.setValid(this.validateCurrentFtNote(serialIdent, abbr, benzVinInfoDTO, statusCKD));
        if (returnValue != 0 && returnValue != 4 && returnValue != 3 && returnValue != 5) {
            FootnoteList fnl_with_same_footnote_number = fnl.getFootnotes(this.getFNoteNum());
            Footnote aFootnote = null;
            for (int counter = 0; counter < fnl_with_same_footnote_number.size(); ++counter) {
                aFootnote = fnl_with_same_footnote_number.get(counter);
                if (aFootnote != null && aFootnote instanceof FootnoteRev9Serial) {
                    if (aFootnote != this) {
                        if (returnValue == 1) {
                            if (aFootnote.isValid(fnl, benzVinInfoDTO, statusCKD) == 8) {
                                if (((FootnoteRev9Serial) aFootnote).isValidByPlusIdent()) {
                                    returnValue = 8;
                                    break;
                                }
                                if (!this.isInValidByMinusIdent()) {
                                    returnValue = 8;
                                    break;
                                }
                            }
                        } else if (returnValue == 8 && aFootnote.isValid(fnl, benzVinInfoDTO, statusCKD) == 1 && ((FootnoteRev9Serial) aFootnote).isInValidByMinusIdent()) {
                            returnValue = 1;
                        }
                    }
                }
            }
        }
        return this.setValid(returnValue);
    }

    private String loadDatacardValues(int chassagg, BenzVinInfoDTO benzVinInfoDTO) {
        this.herstellar = benzVinInfoDTO.getWhc();
        if (chassagg == 4 || chassagg == 5) {
            this.cab = benzVinInfoDTO.getBody();
            if (this.cab != null) {
                this.cab = this.cab.replaceAll(" ", "");
                if (this.cab.length() >= 14) {
                    this.cab = this.cab.substring(7);
                }
            }
            return this.cab;
        }
        if (chassagg == 0 || chassagg == 1) {
            return this.chassis = benzVinInfoDTO.getChassIdent();
        }
        if (chassagg == 2 || chassagg == 3) {
            this.engine = benzVinInfoDTO.getEngine();
            if (this.engine != null && this.engine.length() > 0) {
                this.engine = this.engine.replaceAll(" ", "");
                if (this.engine.length() >= 15) {
                    this.engine = this.engine.substring(9);
                } else if (this.engine.length() >= 14) {
                    this.engine = this.engine.substring(6);
                }
            }
            return this.engine;
        }
        if (chassagg == 12 || chassagg == 13) {
            this.steer = benzVinInfoDTO.getSteering();
            if (this.steer != null) {
                this.steer = this.steer.replaceAll(" ", "");
                if (this.steer.length() >= 14) {
                    this.steer = this.steer.substring(7);
                }
            }
            return this.steer;
        }
        if (chassagg == 10 || chassagg == 11) {
            this.platForm = benzVinInfoDTO.getPlatform();
            if (this.platForm != null) {
                this.platForm = this.platForm.replaceAll(" ", "");
                if (this.platForm.length() >= 14) {
                    this.platForm = this.platForm.substring(7);
                }
            }
            return this.platForm;
        }
        if (chassagg == 16 || chassagg == 17) {
            this.xferCase = benzVinInfoDTO.getTransferCase();
            if (this.xferCase != null) {
                this.xferCase = this.xferCase.replaceAll(" ", "");
                if (this.xferCase.length() >= 14) {
                    this.xferCase = this.xferCase.substring(7);
                }
            }
            return this.xferCase;
        }
        if (chassagg == 8 || chassagg == 9) {
            this.fAxle = benzVinInfoDTO.getFrontAxle2();
            if (this.fAxle != null && this.fAxle.length() > 0) {
                this.fAxle = this.fAxle.replaceAll(" ", "");
                if (this.fAxle.length() >= 14) {
                    this.fAxle = this.fAxle.substring(7);
                }
            } else {
                this.fAxle = benzVinInfoDTO.getFrontAxle1();
                if (this.fAxle != null) {
                    this.fAxle = this.fAxle.replaceAll(" ", "");
                    if (this.fAxle.length() >= 14) {
                        this.fAxle = this.fAxle.substring(7);
                    }
                }
            }
            return this.fAxle;
        }
        if (chassagg == 6 || chassagg == 7) {
            this.rAxle = benzVinInfoDTO.getRearAxle2();
            if (this.rAxle != null && this.rAxle.length() > 0) {
                this.rAxle = this.rAxle.replaceAll(" ", "");
                if (this.rAxle.length() >= 14) {
                    this.rAxle = this.rAxle.substring(7);
                }
            } else {
                this.rAxle = benzVinInfoDTO.getRearAxle1();
                if (this.rAxle != null) {
                    this.rAxle = this.rAxle.replaceAll(" ", "");
                    if (this.rAxle.length() >= 14) {
                        this.rAxle = this.rAxle.substring(7);
                    }
                }
            }
            return this.rAxle;
        }
        if (chassagg == 14 || chassagg == 15) {
            this.transmission = benzVinInfoDTO.getTransmission();
            if (this.transmission != null) {
                this.transmission = this.transmission.replaceAll(" ", "");
                if (this.transmission.length() >= 14) {
                    this.transmission = this.transmission.substring(this.transmission.length() - 8);
                }
            }
            return this.transmission;
        }
        return "";
    }

    private int translateABBR(String abbr) {
        int translation = 0;
        switch (abbr) {
            case "EBF":
                return 1;
            case "EAF":
                return 0;
            case "EAM":
                return 2;
            case "EBM":
                translation = 3;
                break;
            case "EAG":
                translation = 14;
                break;
            case "EBG":
                translation = 15;
                break;
            case "EAA":
                translation = 4;
                break;
            case "EBA":
                translation = 5;
                break;
            case "EAH":
                translation = 6;
                break;
            case "EBH":
                translation = 7;
                break;
            case "EAV":
                translation = 8;
                break;
            case "EBV":
                translation = 9;
                break;
            case "EAL":
                translation = 12;
                break;
            case "EBL":
                translation = 13;
                break;
            case "EAZ":
                translation = 16;
                break;
            case "EBZ":
                translation = 17;
                break;
            case "EAP":
                translation = 10;
                break;
            case "EBP":
               return  11;
            default:
                return 0;
        }
        return translation;
    }

    private int isModelYearValid(String modelYR, BenzVinInfoDTO benzVinInfoDTO, int status) {
        if (benzVinInfoDTO != null && CollectionUtils.isNotEmpty(benzVinInfoDTO.getSaCodeSet()) && StringUtils.isNotBlank(modelYR) && benzVinInfoDTO.getSaCodeSet().contains(modelYR.trim()) && status == 8) {
            return 1;
        }
        return status;
    }

    private int isDateMatching(int validStatus, String inDate, int uptofrom, BenzVinInfoDTO benzVinInfoDTO, boolean isDateOnly) {
        if (benzVinInfoDTO != null) {
            String releaseDate = benzVinInfoDTO.getReleaseDate();
            String deliveryDate = benzVinInfoDTO.getDeliveryDate();
            String val = null;
            if (releaseDate != null && !releaseDate.trim().equals("") && !releaseDate.startsWith("      ")) {
                val = BenzStringUtil.reformatDate(releaseDate);
            } else if (deliveryDate != null && !deliveryDate.trim().equals("") && !deliveryDate.startsWith("      ")) {
                val = BenzStringUtil.reformatDate(deliveryDate);
            }
            if (val == null) {
                return validStatus;
            }
            Integer iDateCmp = new Integer(val);
            Integer iDate = new Integer(inDate);
            if (uptofrom == 0) {
                if (iDateCmp >= iDate) {
                    validStatus = 7;
                } else {
                    validStatus = 6;
                }
            } else if (uptofrom == 1) {
                if (iDateCmp <= iDate) {
                    validStatus = 7;
                } else {
                    validStatus = 6;
                }
            }
        }
        if (!isDateOnly && validStatus == 7) {
            validStatus = 8;
        }
        if (!isDateOnly && validStatus == 6) {
            validStatus = 1;
        }
        return validStatus;
    }

    private int validateCurrentFtNote(String serialIdent, int abbr, BenzVinInfoDTO benzVinInfoDTO, int statusCKD) {
        int valid = 0;
        switch (abbr) {
            case 0: {
                if (this.isPlantCodeOnlyFN()) {
                    valid = this.isPlantCodeValid(this.ident, serialIdent);
                    if (valid == 8 && this.date != null && !this.date.equals("        ")) {
                        valid = this.isDateMatching(valid, this.date, 0, benzVinInfoDTO, false);
                    }
                } else if (this.ident != null && !this.ident.equals("        ")) {
                    valid = this.isChassisSerialValid(this.ident, this.plusIdent, this.minusIdent, this.extraIdents, serialIdent, 0);
                } else if (this.date != null && !this.date.equals("        ")) {
                    valid = this.isDateMatching(valid, this.date, 0, benzVinInfoDTO, true);
                }
                valid = this.isModelYearValid(this.modelyr, benzVinInfoDTO, valid);
                valid = this.isCKDValid(statusCKD, valid);
                break;
            }
            case 1: {
                if (this.isPlantCodeOnlyFN()) {
                    valid = this.isPlantCodeValid(this.ident, serialIdent);
                    if (valid == 8 && this.date != null && !this.date.equals("        ")) {
                        valid = this.isDateMatching(valid, this.date, 1, benzVinInfoDTO, false);
                    }
                } else if (this.ident != null && !this.ident.equals("        ")) {
                    valid = this.isChassisSerialValid(this.ident, this.plusIdent, this.minusIdent, this.extraIdents, serialIdent, 1);
                } else if (this.date != null && !this.date.equals("        ")) {
                    valid = this.isDateMatching(valid, this.date, 1, benzVinInfoDTO, true);
                }
                valid = this.isModelYearValid(this.modelyr, benzVinInfoDTO, valid);
                valid = this.isCKDValid(statusCKD, valid);
                break;
            }
            case 2: {
                if (this.isPlantCodeOnlyFN()) {
                    valid = this.isAggPlantCodeValid(this.ident, serialIdent);
                    if (valid == 8 && this.date != null && !this.date.equals("        ")) {
                        valid = this.isDateMatching(valid, this.date, 1, benzVinInfoDTO, false);
                    }
                } else if (this.ident != null && !this.ident.equals("        ")) {
                    valid = this.isMotorAggValid(this.ident, this.plusIdent, this.minusIdent, this.extraIdents, serialIdent, 0);
                } else if (this.date != null && !this.date.equals("        ")) {
                    valid = this.isDateMatching(valid, this.date, 0, benzVinInfoDTO, true);
                }
                valid = this.isModelYearValid(this.modelyr, benzVinInfoDTO, valid);
                break;
            }
            case 3: {
                if (this.isPlantCodeOnlyFN()) {
                    valid = this.isAggPlantCodeValid(this.ident, serialIdent);
                    if (valid == 8 && this.date != null && !this.date.equals("        ")) {
                        valid = this.isDateMatching(valid, this.date, 1, benzVinInfoDTO, false);
                    }
                } else if (this.ident != null && !this.ident.equals("        ")) {
                    valid = this.isMotorAggValid(this.ident, this.plusIdent, this.minusIdent, this.extraIdents, serialIdent, 1);
                } else if (this.date != null && !this.date.equals("        ")) {
                    valid = this.isDateMatching(valid, this.date, 1, benzVinInfoDTO, true);
                }
                valid = this.isModelYearValid(this.modelyr, benzVinInfoDTO, valid);
                break;
            }
            case 4: {
                if (this.ident != null && !this.ident.equals("        ")) {
                    valid = this.isCabAggValid(this.ident, this.plusIdent, this.minusIdent, this.extraIdents, serialIdent, 0, benzVinInfoDTO);
                } else if (this.date != null && !this.date.equals("        ")) {
                    valid = this.isDateMatching(valid, this.date, 0, benzVinInfoDTO, true);
                }
                valid = this.isModelYearValid(this.modelyr, benzVinInfoDTO, valid);
                break;
            }
            case 5: {
                if (this.ident != null && !this.ident.equals("        ")) {
                    valid = this.isCabAggValid(this.ident, this.plusIdent, this.minusIdent, this.extraIdents, serialIdent, 1, benzVinInfoDTO);
                } else if (this.date != null && !this.date.equals("        ")) {
                    valid = this.isDateMatching(valid, this.date, 1, benzVinInfoDTO, true);
                }
                valid = this.isModelYearValid(this.modelyr, benzVinInfoDTO, valid);
                break;
            }
            case 10: {
                if (this.ident != null && !this.ident.equals("        ")) {
                    valid = this.isOtherAggValid(this.ident, this.plusIdent, this.minusIdent, this.extraIdents, serialIdent, 0);
                } else if (this.date != null && !this.date.equals("        ")) {
                    valid = this.isDateMatching(valid, this.date, 0, benzVinInfoDTO, true);
                }
                valid = this.isModelYearValid(this.modelyr, benzVinInfoDTO, valid);
                break;
            }
            case 11: {
                if (this.ident != null && !this.ident.equals("        ")) {
                    valid = this.isOtherAggValid(this.ident, this.plusIdent, this.minusIdent, this.extraIdents, serialIdent, 1);
                } else if (this.date != null && !this.date.equals("        ")) {
                    valid = this.isDateMatching(valid, this.date, 1, benzVinInfoDTO, true);
                }
                valid = this.isModelYearValid(this.modelyr, benzVinInfoDTO, valid);
                break;
            }
            case 12: {
                if (this.ident != null && !this.ident.equals("        ")) {
                    valid = this.isOtherAggValid(this.ident, this.plusIdent, this.minusIdent, this.extraIdents, serialIdent, 0);
                } else if (this.date != null && !this.date.equals("        ")) {
                    valid = this.isDateMatching(valid, this.date, 0, benzVinInfoDTO, true);
                }
                valid = this.isModelYearValid(this.modelyr, benzVinInfoDTO, valid);
                break;
            }
            case 13: {
                if (this.ident != null && !this.ident.equals("        ")) {
                    valid = this.isOtherAggValid(this.ident, this.plusIdent, this.minusIdent, this.extraIdents, serialIdent, 1);
                } else if (this.date != null && !this.date.equals("        ")) {
                    valid = this.isDateMatching(valid, this.date, 1, benzVinInfoDTO, true);
                }
                valid = this.isModelYearValid(this.modelyr, benzVinInfoDTO, valid);
                break;
            }
            case 16: {
                if (this.ident != null && !this.ident.equals("        ")) {
                    valid = this.isOtherAggValid(this.ident, this.plusIdent, this.minusIdent, this.extraIdents, serialIdent, 0);
                } else if (this.date != null && !this.date.equals("        ")) {
                    valid = this.isDateMatching(valid, this.date, 0, benzVinInfoDTO, true);
                }
                valid = this.isModelYearValid(this.modelyr, benzVinInfoDTO, valid);
                break;
            }
            case 17: {
                if (this.ident != null && !this.ident.equals("        ")) {
                    valid = this.isOtherAggValid(this.ident, this.plusIdent, this.minusIdent, this.extraIdents, serialIdent, 1);
                } else if (this.date != null && !this.date.equals("        ")) {
                    valid = this.isDateMatching(valid, this.date, 1, benzVinInfoDTO, true);
                }
                valid = this.isModelYearValid(this.modelyr, benzVinInfoDTO, valid);
                break;
            }
            case 14: {
                if (this.isPlantCodeOnlyFN()) {
                    valid = this.isAggPlantCodeValid(this.ident, serialIdent);
                    if (valid == 8 && this.date != null && !this.date.equals("        ")) {
                        valid = this.isDateMatching(valid, this.date, 1, benzVinInfoDTO, false);
                    }
                } else if (this.ident != null && !this.ident.equals("        ")) {
                    valid = this.isTransAggValid(this.ident, this.plusIdent, this.minusIdent, this.extraIdents, serialIdent, 0);
                } else if (this.date != null && !this.date.equals("        ")) {
                    valid = this.isDateMatching(valid, this.date, 0, benzVinInfoDTO, true);
                }
                valid = this.isModelYearValid(this.modelyr, benzVinInfoDTO, valid);
                break;
            }
            case 15: {
                if (this.isPlantCodeOnlyFN()) {
                    valid = this.isAggPlantCodeValid(this.ident, serialIdent);
                    if (valid == 8 && this.date != null && !this.date.equals("        ")) {
                        valid = this.isDateMatching(valid, this.date, 1, benzVinInfoDTO, false);
                    }
                } else if (this.ident != null && !this.ident.equals("        ")) {
                    valid = this.isTransAggValid(this.ident, this.plusIdent, this.minusIdent, this.extraIdents, serialIdent, 1);
                } else if (this.date != null && !this.date.equals("        ")) {
                    valid = this.isDateMatching(valid, this.date, 1, benzVinInfoDTO, true);
                }
                valid = this.isModelYearValid(this.modelyr, benzVinInfoDTO, valid);
                break;
            }
            case 6: {
                if (this.ident != null && !this.ident.equals("        ")) {
                    valid = this.isOtherAggValid(this.ident, this.plusIdent, this.minusIdent, this.extraIdents, serialIdent, 0);
                } else if (this.date != null && !this.date.equals("        ")) {
                    valid = this.isDateMatching(valid, this.date, 0, benzVinInfoDTO, true);
                }
                valid = this.isModelYearValid(this.modelyr, benzVinInfoDTO, valid);
                break;
            }
            case 7: {
                if (this.ident != null && !this.ident.equals("        ")) {
                    valid = this.isOtherAggValid(this.ident, this.plusIdent, this.minusIdent, this.extraIdents, serialIdent, 1);
                } else if (this.date != null && !this.date.equals("        ")) {
                    valid = this.isDateMatching(valid, this.date, 1, benzVinInfoDTO, true);
                }
                valid = this.isModelYearValid(this.modelyr, benzVinInfoDTO, valid);
                break;
            }
            case 8: {
                if (this.ident != null && !this.ident.equals("        ")) {
                    valid = this.isOtherAggValid(this.ident, this.plusIdent, this.minusIdent, this.extraIdents, serialIdent, 0);
                } else if (this.date != null && !this.date.equals("        ")) {
                    valid = this.isDateMatching(valid, this.date, 0, benzVinInfoDTO, true);
                }
                valid = this.isModelYearValid(this.modelyr, benzVinInfoDTO, valid);
                break;
            }
            case 9: {
                if (this.ident != null && !this.ident.equals("        ")) {
                    valid = this.isOtherAggValid(this.ident, this.plusIdent, this.minusIdent, this.extraIdents, serialIdent, 1);
                } else if (this.date != null && !this.date.equals("        ")) {
                    valid = this.isDateMatching(valid, this.date, 1, benzVinInfoDTO, true);
                }
                valid = this.isModelYearValid(this.modelyr, benzVinInfoDTO, valid);
                break;
            }
            default:
                break;
        }
        return valid;
    }

    private int isCKDValid(int statusCKD, int valid) {
        if (statusCKD == 0) {
            return valid;
        }
        if (statusCKD == 1 && !this.isCKD()) {
            return valid;
        }
        if (statusCKD == 2 && this.isCKD()) {
            return valid;
        }
        return 4;
    }

    private int isAggPlantCodeValid(String fnIdent, String ident) {
        if (fnIdent == null || ident == null || fnIdent.isEmpty() || ident.isEmpty()) {
            return 0;
        }
        char serialIdentPlantCode = ident.charAt(0);
        char mainIdentPlantCode = fnIdent.charAt(0);
        if (serialIdentPlantCode == mainIdentPlantCode) {
            return 8;
        }
        return 3;
    }

    private int isChassisSerialValid(String mainIdent, char plusIdent, char minusIdent, String spareIdent, String serialIdent, int tofrom) {
        String formattedIdent = null;
        String serialPlantCodeGroup = null;
        String footnotePlantCodeGroup = null;
        int valid = 1;
        if (this.plantCodes == null || this.plantCodes.trim().equals("")) {
            return 0;
        }
        if (this.plantCodes.indexOf(serialIdent.charAt(1)) != -1) {
            serialPlantCodeGroup = this.getPlantCodeGroup(this.plantCodes, serialIdent.charAt(1));
        }
        if (serialPlantCodeGroup == null) {
            return 0;
        }
        formattedIdent = this.checkNewFTNoteFormat(mainIdent);
        if (formattedIdent.length() == 0) {
            return 0;
        }
        if (formattedIdent.length() >= 7) {
            char cPlantCode;
            if (formattedIdent.length() == 7) {
                cPlantCode = formattedIdent.charAt(0);
            } else {
                cPlantCode = formattedIdent.charAt(1);
            }
            if (serialPlantCodeGroup.indexOf(cPlantCode) != -1) {
                footnotePlantCodeGroup = this.getPlantCodeGroup(this.plantCodes, cPlantCode);
                if (footnotePlantCodeGroup.equals(serialPlantCodeGroup)) {
                    int res = serialPlantCodeGroup.indexOf(serialIdent.charAt(1));
                    String millionthString;
                    if (res >= 10) {
                        millionthString = "" + res;
                    } else {
                        millionthString = "0" + res;
                    }
                    String serialIdentToCompare = millionthString + serialIdent.substring(2, 8);
                    res = footnotePlantCodeGroup.indexOf(cPlantCode);
                    if (res >= 10) {
                        millionthString = "" + res;
                    } else {
                        millionthString = "0" + res;
                    }
                    String footnoteIdentToCompare;
                    if (formattedIdent.length() == 7) {
                        footnoteIdentToCompare = millionthString + formattedIdent.substring(1, 7);
                    } else {
                        footnoteIdentToCompare = millionthString + formattedIdent.substring(2, 8);
                    }
                    if (tofrom == 0) {
                        if (serialIdentToCompare.compareTo(footnoteIdentToCompare) >= 0) {
                            valid = 8;
                        } else {
                            valid = 1;
                        }
                    } else if (tofrom == 1) {
                        if (serialIdentToCompare.compareTo(footnoteIdentToCompare) <= 0) {
                            valid = 8;
                        } else {
                            valid = 1;
                        }
                    }
                } else {
                    if (footnotePlantCodeGroup == null || footnotePlantCodeGroup.isEmpty()) {
                        return 0;
                    }
                    return 3;
                }
            } else {
                footnotePlantCodeGroup = this.getPlantCodeGroup(this.plantCodes, cPlantCode);
                if (footnotePlantCodeGroup == null || footnotePlantCodeGroup.isEmpty()) {
                    return 0;
                }
                return 3;
            }
        } else if (tofrom == 0) {
            if (!formattedIdent.equals("")) {
                if (serialIdent.substring(2, 8).compareTo(formattedIdent.substring(0, 6)) >= 0) {
                    valid = 8;
                } else {
                    valid = 1;
                }
            }
        } else if (tofrom == 1) {
            if (serialIdent.substring(2, 8).compareTo(formattedIdent.substring(0, 6)) <= 0) {
                valid = 8;
            } else {
                valid = 1;
            }
        }
        if (valid == 1) {
            if (plusIdent == 'P' && this.isIdentFound(serialIdent, spareIdent)) {
                this.validByPlusIdent = true;
                valid = 8;
            }
        } else if (valid == 8 && minusIdent == 'M' && this.isIdentFound(serialIdent, spareIdent)) {
            this.inValidByMinusIdent = true;
            valid = 1;
        }
        return valid;
    }

    private int isPlantCodeValid(String identFromFootnote, String identFromChassis) {
        int valid = 3;
        String chassisPlantCodeGroup = null;
        String footnotePlantCodeGroup = null;
        if (this.plantCodes == null || this.plantCodes.trim().equals("") || identFromChassis == null || identFromChassis.isEmpty()) {
            return 0;
        }
        if (this.plantCodes.indexOf(identFromChassis.charAt(1)) != -1) {
            chassisPlantCodeGroup = this.getPlantCodeGroup(this.plantCodes, identFromChassis.charAt(1));
        }
        if (chassisPlantCodeGroup == null) {
            return 0;
        }
        char plantCodeFromFootnote = identFromFootnote.charAt(0);
        if (chassisPlantCodeGroup.indexOf(plantCodeFromFootnote) != -1) {
            footnotePlantCodeGroup = this.getPlantCodeGroup(this.plantCodes, plantCodeFromFootnote);
        }
        if (footnotePlantCodeGroup != null && footnotePlantCodeGroup.equals(chassisPlantCodeGroup)) {
            valid = 8;
        } else {
            valid = 3;
        }
        return valid;
    }

    private int isMotorAggValid(String mainIdent, char plusIdent, char minusIdent, String spareIdent, String serialIdent, int uptofrom) {
        int valid = 0;
        String tmpIdent = null;
        String tmpMainIdent = null;
        int len = serialIdent.length();
        if (len == 0) {
            return 0;
        }
        if (mainIdent.length() == 8 && mainIdent.charAt(0) != ' ' && mainIdent.charAt(1) != ' ' && !mainIdent.substring(2).startsWith("      ")) {
            char serialIdentPlantCode = serialIdent.charAt(0);
            char mainIdentPlantCode = mainIdent.charAt(0);
            if (serialIdentPlantCode != mainIdentPlantCode) {
                return 3;
            }
            tmpIdent = serialIdent.substring(serialIdent.length() - 7);
            tmpMainIdent = mainIdent.substring(mainIdent.length() - 7);
        } else if (mainIdent.length() == 8 && mainIdent.charAt(0) != ' ' && mainIdent.charAt(1) == ' ' && !mainIdent.substring(2).startsWith("      ")) {
            char serialIdentPlantCode = serialIdent.charAt(0);
            char mainIdentPlantCode = mainIdent.charAt(0);
            if (serialIdentPlantCode != mainIdentPlantCode) {
                return 3;
            }
            tmpIdent = serialIdent.substring(serialIdent.length() - 6);
            tmpMainIdent = mainIdent.substring(mainIdent.length() - 6);
        } else if (mainIdent.length() == 8 && mainIdent.charAt(0) == ' ' && mainIdent.charAt(1) != ' ' && !mainIdent.substring(2).startsWith("      ")) {
            tmpIdent = serialIdent.substring(serialIdent.length() - 7);
            tmpMainIdent = mainIdent.substring(mainIdent.length() - 7);
        } else if (mainIdent.startsWith("  ") && !mainIdent.substring(2).startsWith("      ")) {
            if (len == 9) {
                tmpIdent = serialIdent.substring(3);
            } else if (len == 8) {
                tmpIdent = serialIdent.substring(2);
            }
            tmpMainIdent = mainIdent.substring(2);
        } else if (mainIdent.charAt(0) != ' ' && mainIdent.charAt(1) != ' ' && !mainIdent.substring(2).startsWith("      ")) {
            if (mainIdent.charAt(0) != serialIdent.charAt(0)) {
                return 3;
            }
            if (len == 8) {
                tmpIdent = serialIdent;
            } else if (len == 9) {
                return 0;
            }
            tmpMainIdent = mainIdent;
        } else if (mainIdent.startsWith(" ") && !mainIdent.substring(1).startsWith("      ")) {
            if (len == 9) {
                tmpIdent = serialIdent.substring(3);
            } else {
                if (len != 8) {
                    return 0;
                }
                tmpIdent = serialIdent.substring(2);
            }
            tmpMainIdent = mainIdent.substring(2);
        }
        if (tmpIdent == null) {
            valid = 0;
        } else if (uptofrom == 0) {
            if (tmpIdent.compareTo(tmpMainIdent) >= 0) {
                valid = 8;
            } else {
                valid = 1;
            }
        } else if (uptofrom == 1) {
            if (tmpIdent.compareTo(tmpMainIdent) <= 0) {
                valid = 8;
            } else {
                valid = 1;
            }
        }
        if (valid == 1) {
            if (plusIdent == 'P' && this.isIdentFound(serialIdent, spareIdent)) {
                this.validByPlusIdent = true;
                valid = 8;
            }
        } else if (valid == 8 && minusIdent == 'M' && this.isIdentFound(serialIdent, spareIdent)) {
            this.inValidByMinusIdent = true;
            valid = 1;
        }
        return valid;
    }

    private int isCabAggValid(String mainIdent, char plusIdent, char minusIdent, String spareIdent, String serialIdent, int uptofrom, BenzVinInfoDTO benzVinInfoDTO) {
        int valid = 0;
        String tmpIdent = null;
        String tmpMainIdent = null;
        String classes = "34567";
        if (benzVinInfoDTO.getVehClass().equals("2")) {
            tmpIdent = serialIdent.substring(1);
            tmpMainIdent = mainIdent.substring(2);
        } else if (classes.indexOf(benzVinInfoDTO.getVehClass().charAt(0)) != -1) {
            if (mainIdent.startsWith("  ") && !mainIdent.substring(2).startsWith("      ")) {
                tmpIdent = serialIdent.substring(2, 8);
                tmpMainIdent = mainIdent.substring(2);
            } else {
                if (mainIdent.charAt(0) != ' ' || mainIdent.charAt(1) == ' ' || mainIdent.substring(2).startsWith("      ")) {
                    return 0;
                }
                if (serialIdent.charAt(0) != '4' && serialIdent.charAt(0) != '5') {
                    return 0;
                }
                tmpIdent = serialIdent;
                tmpMainIdent = mainIdent.substring(1);
            }
        }
        if (uptofrom == 0) {
            if (tmpIdent.compareTo(tmpMainIdent) >= 0) {
                valid = 8;
            } else {
                valid = 1;
            }
        } else if (uptofrom == 1) {
            if (tmpIdent.compareTo(tmpMainIdent) <= 0) {
                valid = 8;
            } else {
                valid = 1;
            }
        }
        if (valid == 1) {
            if (plusIdent == 'P' && this.isIdentFound(tmpIdent, spareIdent)) {
                this.validByPlusIdent = true;
                valid = 8;
            }
        } else if (valid == 8 && minusIdent == 'M' && this.isIdentFound(tmpIdent, spareIdent)) {
            this.inValidByMinusIdent = true;
            valid = 1;
        }
        return valid;
    }

    private int isTransAggValid(String mainIdent, char plusIdent, char minusIdent, String spareIdent, String serialIdent, int uptofrom) {
        int valid = 0;
        String tmpIdent = null;
        String tmpMainIdent = null;
        if (serialIdent == null || serialIdent.length() <= 0) {
            return 0;
        }
        if (mainIdent.charAt(0) != ' ' && mainIdent.charAt(1) != ' ' && mainIdent.length() == 6) {
            tmpIdent = serialIdent.substring(serialIdent.length() - 6);
            tmpMainIdent = mainIdent;
        } else if (mainIdent.charAt(0) != ' ' && mainIdent.length() == 7) {
            tmpIdent = serialIdent.substring(serialIdent.length() - 7);
            tmpMainIdent = mainIdent;
        } else if (mainIdent.length() == 8 && mainIdent.charAt(0) != ' ' && mainIdent.charAt(1) != ' ' && !mainIdent.substring(2).startsWith("      ")) {
            char serialIdentPlantCode = serialIdent.charAt(0);
            char mainIdentPlantCode = mainIdent.charAt(0);
            if (serialIdentPlantCode != mainIdentPlantCode) {
                return 3;
            }
            tmpIdent = serialIdent.substring(serialIdent.length() - 7);
            tmpMainIdent = mainIdent.substring(mainIdent.length() - 7);
        } else if (mainIdent.length() == 8 && mainIdent.charAt(0) != ' ' && mainIdent.charAt(1) == ' ' && !mainIdent.substring(2).startsWith("      ")) {
            char serialIdentPlantCode = serialIdent.charAt(0);
            char mainIdentPlantCode = mainIdent.charAt(0);
            if (serialIdentPlantCode != mainIdentPlantCode) {
                return 3;
            }
            tmpIdent = serialIdent.substring(serialIdent.length() - 6);
            tmpMainIdent = mainIdent.substring(mainIdent.length() - 6);
        } else if (mainIdent.length() == 8 && mainIdent.charAt(0) == ' ' && mainIdent.charAt(1) != ' ' && !mainIdent.substring(2).startsWith("      ")) {
            tmpIdent = serialIdent.substring(serialIdent.length() - 7);
            tmpMainIdent = mainIdent.substring(mainIdent.length() - 7);
        } else if (mainIdent.startsWith("  ") && !mainIdent.substring(2).startsWith("      ")) {
            tmpIdent = serialIdent.substring(2);
            tmpMainIdent = mainIdent.substring(2);
        } else if (mainIdent.charAt(0) == ' ' && mainIdent.charAt(1) != ' ' && !mainIdent.substring(2).startsWith("      ")) {
            if (!Character.isDigit(serialIdent.charAt(0)) && !Character.isDigit(serialIdent.charAt(1))) {
                return 0;
            }
            tmpIdent = serialIdent;
            tmpMainIdent = mainIdent.substring(1);
        }
        int length = tmpMainIdent.length();
        tmpIdent = tmpIdent.substring(tmpIdent.length() - length);
        if (tmpIdent == null) {
            valid = 0;
        } else if (uptofrom == 0) {
            if (tmpIdent.compareTo(tmpMainIdent) >= 0) {
                valid = 8;
            } else {
                valid = 1;
            }
        } else if (uptofrom == 1) {
            if (tmpIdent.compareTo(tmpMainIdent) <= 0) {
                valid = 8;
            } else {
                valid = 1;
            }
        }
        if (valid == 1) {
            if (plusIdent == 'P' && this.isIdentFound(serialIdent, spareIdent)) {
                this.validByPlusIdent = true;
                valid = 8;
            }
        } else if (valid == 8 && minusIdent == 'M' && this.isIdentFound(serialIdent, spareIdent)) {
            this.inValidByMinusIdent = true;
            valid = 1;
        }
        return valid;
    }

    private int isOtherAggValid(String mainIdent, char plusIdent, char minusIdent, String spareIdent, String serialIdent, int uptofrom) {
        int valid = 0;
        String tmpIdent = null;
        String tmpMainIdent = null;
        if (serialIdent == null || serialIdent.length() <= 0) {
            return 0;
        }
        if (mainIdent.startsWith("  ") && !mainIdent.substring(2).startsWith("      ")) {
            tmpIdent = serialIdent.substring(1);
            tmpMainIdent = mainIdent.substring(2);
        } else if (mainIdent.charAt(0) == ' ' && mainIdent.charAt(1) != ' ' && !mainIdent.substring(2).startsWith("      ")) {
            if (!Character.isDigit(serialIdent.charAt(0)) && !Character.isDigit(serialIdent.charAt(1))) {
                return 0;
            }
            tmpIdent = serialIdent;
            tmpMainIdent = mainIdent.substring(1);
        }
        if (uptofrom == 0) {
            if (tmpIdent.compareTo(tmpMainIdent) >= 0) {
                valid = 8;
            } else {
                valid = 1;
            }
        } else if (uptofrom == 1) {
            if (tmpIdent.compareTo(tmpMainIdent) <= 0) {
                valid = 8;
            } else {
                valid = 1;
            }
        }
        if (valid == 1) {
            if (plusIdent == 'P' && this.isIdentFound(tmpIdent, spareIdent)) {
                this.validByPlusIdent = true;
                valid = 8;
            }
        } else if (valid == 8 && minusIdent == 'M' && this.isIdentFound(tmpIdent, spareIdent)) {
            this.inValidByMinusIdent = true;
            valid = 1;
        }
        return valid;
    }

    private boolean isIdentFound(String serialIdent, String spareIdent) {
        for (int len = spareIdent.length(), i = 0; i < len; i += 8) {
            String tmpSpareIdent = spareIdent.substring(i, i + 8);
            if (!tmpSpareIdent.startsWith("        ")) {
                String tmpFormattedIdent = this.checkNewFTNoteFormat(tmpSpareIdent);
                int formattedIdentLen = tmpFormattedIdent.length();
                int serialIdentLen = serialIdent.length();
                if (formattedIdentLen == 7 && serialIdentLen == 7 && tmpFormattedIdent.equals(serialIdent)) {
                    return true;
                }
                if (formattedIdentLen == 7 && serialIdentLen == 8 && tmpFormattedIdent.substring(0, 7).equals(serialIdent.substring(1, 8))) {
                    return true;
                }
                if (formattedIdentLen == 8 && serialIdentLen == 8 && tmpFormattedIdent.equals(serialIdent)) {
                    return true;
                }
                if (formattedIdentLen == 6 && serialIdentLen == 8 && tmpFormattedIdent.substring(0, 6).equals(serialIdent.substring(2, 8))) {
                    return true;
                }
            }
        }
        return false;
    }

    private String checkNewFTNoteFormat(String mainIdent) {
        String formattedIdent = "";
        if (!Character.isWhitespace(mainIdent.charAt(0)) && Character.isWhitespace(mainIdent.charAt(1)) && this.isSixNums(mainIdent.substring(2, 8))) {
            formattedIdent = mainIdent.substring(0, 1) + mainIdent.substring(2, 8);
        } else if (!Character.isWhitespace(mainIdent.charAt(0)) && !Character.isWhitespace(mainIdent.charAt(1)) && this.isSixNums(mainIdent.substring(2, 8))) {
            formattedIdent = mainIdent;
        } else if (Character.isWhitespace(mainIdent.charAt(0)) && Character.isWhitespace(mainIdent.charAt(1)) && this.isSixNums(mainIdent.substring(2, 8))) {
            formattedIdent = mainIdent.trim();
        } else if (Character.isWhitespace(mainIdent.charAt(0)) && !Character.isWhitespace(mainIdent.charAt(1)) && this.isSixNums(mainIdent.substring(2, 8))) {
            formattedIdent = mainIdent.trim();
        }
        return formattedIdent;
    }

    private boolean isSixNums(String serialIdent) {
        for (int i = 0; i < 6; ++i) {
            if (!Character.isDigit(serialIdent.charAt(i))) {
                return false;
            }
        }
        return true;
    }

    private String getPlantCodeGroup(String pltCodes, char cPlantCode) {
        int j;
        String tmpPlantCodes;
        String tmpPlantCodes2;
        for (j = 0, tmpPlantCodes = pltCodes; (j = tmpPlantCodes.lastIndexOf(",")) != -1; tmpPlantCodes = tmpPlantCodes.substring(0, j)) {
            tmpPlantCodes2 = tmpPlantCodes.substring(j + 1);
            if (tmpPlantCodes2.indexOf(cPlantCode) != -1) {
                return tmpPlantCodes2;
            }
        }
        if (tmpPlantCodes.indexOf(cPlantCode) != -1) {
            return tmpPlantCodes;
        }
        return pltCodes;
    }

    private void clear() {
        this.ident = "";
        this.date = "";
        this.modelyr = "";
        this.plusIdent = ' ';
        this.minusIdent = ' ';
        this.extraIdents = "";
        this.validByPlusIdent = false;
        this.inValidByMinusIdent = false;
    }

    private void setValues() {
        this.clear();
        int textLength = this.text.length();
        if (textLength > 0) {
            if (this.abbr.equals("EAF") || this.abbr.equals("EBF")) {
                String tmpString = "";
                if (textLength >= 8) {
                    tmpString = this.text.substring(0, 8);
                } else {
                    tmpString = this.text;
                }
                tmpString = tmpString.trim();
                if (tmpString.length() == 1) {
                    this.ident = tmpString + "       ";
                } else if (tmpString.length() >= 6) {
                    this.ident = tmpString;
                }
            }
            if (this.abbr.equals("EAG") || this.abbr.equals("EBG")) {
                String tmpString = "";
                if (textLength >= 8) {
                    tmpString = this.text.substring(0, 8);
                } else {
                    tmpString = this.text;
                }
                tmpString = tmpString.trim();
                if (tmpString.length() == 1) {
                    this.ident = tmpString + "       ";
                } else if (tmpString.length() >= 6) {
                    this.ident = tmpString;
                }
            } else if (this.abbr.equals("EAM") || this.abbr.equals("EBM")) {
                String tmpString = "";
                if (textLength >= 8) {
                    tmpString = this.text.substring(0, 8);
                } else {
                    tmpString = this.text;
                }
                tmpString = tmpString.trim();
                if (tmpString.length() == 1) {
                    this.ident = tmpString + "       ";
                } else if (tmpString.length() >= 6) {
                    this.ident = tmpString;
                }
            } else {
                String tmpString = "";
                if (textLength >= 8) {
                    tmpString = this.text.substring(0, 8);
                } else {
                    tmpString = this.text;
                }
                tmpString = tmpString.trim();
                if (tmpString.length() == 1) {
                    this.ident = tmpString + "       ";
                } else if (tmpString.length() >= 6) {
                    this.ident = tmpString;
                }
            }
        }
        if (this.ident.trim().length() == 1) {
            this.setPlantCodeOnlyFN(true);
        }
        this.ident = "        ".substring(this.ident.length()) + this.ident;
        if (textLength > 8) {
            if (textLength < 16) {
                log.error("脚注长度小于16,请检查对应数据,脚注:{}", this.text);
            }
            this.date = this.text.substring(8, 16);
        } else {
            this.date = "        ";
        }
        if (textLength > 16) {
            if (textLength < 21) {
                log.error("脚注长度小于21,请检查对应数据,脚注:{}", this.text);
            }
            this.modelyr = this.text.substring(16, 21);
        } else {
            this.modelyr = "     ";
        }
        if (textLength > 21) {
            this.plusIdent = this.text.substring(21, 22).charAt(0);
        } else {
            this.plusIdent = ' ';
        }
        if (textLength > 22) {
            this.minusIdent = this.text.substring(22, 23).charAt(0);
        } else {
            this.minusIdent = ' ';
        }
        if (textLength > 23) {
            this.extraIdents = this.text.substring(23);
        } else {
            this.extraIdents = "";
        }
    }

    @Override
    public String getIdent() {
        return this.ident;
    }

    @Override
    public String getDate() {
        return this.date;
    }

    @Override
    public String getModelyr() {
        return this.modelyr;
    }

    private boolean isPlantCodeOnlyFN() {
        return this.plantCodeOnlyFN;
    }

    private void setPlantCodeOnlyFN(boolean plantCodeOnlyFN) {
        this.plantCodeOnlyFN = plantCodeOnlyFN;
    }
}
